const regExp_phoneNumber = new RegExp(/^(\+?0?86\-?)?1[3456789]\d{9}$/);

export type FromRulesType = ReturnType<typeof getRules>;

const getRules = () => {
    return {
        phoneNumber: [
            {
                required: true,
                validator: (rule, val, callback) => {
                    if (!val) {
                        return Promise.reject('手机号不能为空');
                    }
                    if (!regExp_phoneNumber.test(val)) return Promise.reject('手机号格式不正确');
                    return Promise.resolve();
                },
            },
        ],
        code: [
            {
                required: true,
                validator: (rule, val, callback) => {
                    if (!val) return Promise.reject('验证不能为空');
                    return Promise.resolve();
                },
            },
        ],
    };
};

export { getRules };
